package cn.tedu.lucky.draw.server.controller;

import cn.tedu.lucky.draw.server.common.annotation.OperationLog;
import cn.tedu.lucky.draw.server.common.result.JsonResult;
import cn.tedu.lucky.draw.server.protocol.po.Prize;
import cn.tedu.lucky.draw.server.protocol.query.PrizeQuery;
import cn.tedu.lucky.draw.server.service.IPrizeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @RestController:@Controller+@ResponseBody
 * @Controller:是Spring中用于表示控制器的注解，该类负责处理客户端的请求，并返回相应的结果
 * @ResponseBody：是Spring框架中的一个注解，用于标识方法的返回结果直接写入到HTTP响应体中
 */
@RestController
@CrossOrigin //表示跨域处理
public class PrizeController {
    /**
     * /draw/prize/findAll
     */
    @Autowired
    private IPrizeService prizeService;

    @PostMapping("/draw/prize/findAll")
    public JsonResult<List<Prize>> findAll(@RequestBody PrizeQuery prizeQuery) {
        List<Prize> prizeList = prizeService.findAll(prizeQuery);
        return JsonResult.ok(prizeList);
    }

    @OperationLog(operation = "新增奖品")
    @PostMapping("/draw/prize/save")
    public JsonResult save(@RequestBody Prize prize) {
        prizeService.save(prize);
        return JsonResult.ok();
    }

    @GetMapping("/draw/prize/findPrize/{id}")
    public JsonResult<List<Prize>> findPrizesByActivityId(@PathVariable Long id) {
        List<Prize> list = prizeService.findPrizesByActivityId(id);
        return JsonResult.ok(list);
    }

    @GetMapping("/draw/price/noBindPrize/{id}")
    public JsonResult<List<Prize>> findNoBindPrize(@PathVariable Long id){
        List<Prize> prizeList=prizeService.findNoBindPrize(id);
        return JsonResult.ok(prizeList);
    }
}
